module Input
  
  Q     = 32
  W     = 33
  E     = 34
  ER    = 35
  T     = 36
  YI    = 37
  U     = 38
  I     = 39
  O     = 40
  P     = 41
  
  class << self
    alias old_self_button_to_key_piano :buttonToKey
  end
  
  def self.buttonToKey(button)
    #Teclado
    return [0x51] if button == Input::Q
    return [0x57] if button == Input::W
    return [0x45] if button == Input::E  
    return [0x52] if button == Input::ER     
    return [0x54] if button == Input::T      
    return [0x59] if button == Input::YI      
    return [0x55] if button == Input::U         
    return [0x49] if button == Input::I       
    return [0x4F] if button == Input::O    
    return [0x50] if button == Input::P       
    
    self.old_self_button_to_key_piano(button)
  end
end


def pbPiano
  viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  viewport.z=99999
  sprites={}
  
  $game_system.bgm_memorize
  pbBGMPlay("blank")
  
  sprites["bg"]=Sprite.new
  sprites["bg"].z=9
  sprites["bg"].bitmap= BitmapCache.load_bitmap("Graphics/Pictures/Piano/background")
  
  sprites["teclaDo"]=IconSprite.new(0,0,viewport)
  sprites["teclaDo"].setBitmap("Graphics/Pictures/Piano/teclaIz")
  sprites["teclaDo"].x =4
  sprites["teclaDo"].y =170
  #sprites["teclaDo"].visible = false
  
  sprites["teclaDo#"]=IconSprite.new(0,0,viewport)
  sprites["teclaDo#"].setBitmap("Graphics/Pictures/Piano/teclaNeg")
  sprites["teclaDo#"].x =36
  sprites["teclaDo#"].y =170
  sprites["teclaDo#"].visible = false
  
  sprites["teclaRe"]=IconSprite.new(0,0,viewport)
  sprites["teclaRe"].setBitmap("Graphics/Pictures/Piano/teclaCen")
  sprites["teclaRe"].x =54
  sprites["teclaRe"].y =170
  sprites["teclaRe"].visible = false
  
  sprites["teclaRe#"]=IconSprite.new(0,0,viewport)
  sprites["teclaRe#"].setBitmap("Graphics/Pictures/Piano/teclaNeg")
  sprites["teclaRe#"].x =88
  sprites["teclaRe#"].y =170
  sprites["teclaRe#"].visible = false
  
  sprites["teclaMi"]=IconSprite.new(0,0,viewport)
  sprites["teclaMi"].setBitmap("Graphics/Pictures/Piano/teclaDer")
  sprites["teclaMi"].x =106
  sprites["teclaMi"].y =170
  sprites["teclaMi"].visible = false
  
  sprites["teclaFa"]=IconSprite.new(0,0,viewport)
  sprites["teclaFa"].setBitmap("Graphics/Pictures/Piano/teclaIz")
  sprites["teclaFa"].x =156
  sprites["teclaFa"].y =170
  sprites["teclaFa"].visible = false
  
  sprites["teclaFa#"]=IconSprite.new(0,0,viewport)
  sprites["teclaFa#"].setBitmap("Graphics/Pictures/Piano/teclaNeg")
  sprites["teclaFa#"].x =188
  sprites["teclaFa#"].y =170
  sprites["teclaFa#"].visible = false
  
  sprites["teclaSol"]=IconSprite.new(0,0,viewport)
  sprites["teclaSol"].setBitmap("Graphics/Pictures/Piano/teclaCen")
  sprites["teclaSol"].x =206
  sprites["teclaSol"].y =170
  sprites["teclaSol"].visible = false
  
  sprites["teclaSol#"]=IconSprite.new(0,0,viewport)
  sprites["teclaSol#"].setBitmap("Graphics/Pictures/Piano/teclaNeg")
  sprites["teclaSol#"].x =240
  sprites["teclaSol#"].y =170
  sprites["teclaSol#"].visible = false
  
  sprites["teclaLa"]=IconSprite.new(0,0,viewport)
  sprites["teclaLa"].setBitmap("Graphics/Pictures/Piano/teclaCen")
  sprites["teclaLa"].x =258
  sprites["teclaLa"].y =170
  sprites["teclaLa"].visible = false
  
  sprites["teclaLa#"]=IconSprite.new(0,0,viewport)
  sprites["teclaLa#"].setBitmap("Graphics/Pictures/Piano/teclaNeg")
  sprites["teclaLa#"].x =292
  sprites["teclaLa#"].y =170
  sprites["teclaLa#"].visible = false
  
  sprites["teclaSi"]=IconSprite.new(0,0,viewport)
  sprites["teclaSi"].setBitmap("Graphics/Pictures/Piano/teclaDer")
  sprites["teclaSi"].x =310
  sprites["teclaSi"].y =170
  sprites["teclaSi"].visible = false
  
  sprites["teclaDo2"]=IconSprite.new(0,0,viewport)
  sprites["teclaDo2"].setBitmap("Graphics/Pictures/Piano/teclaIz")
  sprites["teclaDo2"].x =360
  sprites["teclaDo2"].y =170
  sprites["teclaDo2"].visible = false
  
  sprites["teclaDo2#"]=IconSprite.new(0,0,viewport)
  sprites["teclaDo2#"].setBitmap("Graphics/Pictures/Piano/teclaNeg")
  sprites["teclaDo2#"].x =392
  sprites["teclaDo2#"].y =170
  sprites["teclaDo2#"].visible = false
  
  sprites["teclaRe2"]=IconSprite.new(0,0,viewport)
  sprites["teclaRe2"].setBitmap("Graphics/Pictures/Piano/teclaCen")
  sprites["teclaRe2"].x =410
  sprites["teclaRe2"].y =170
  sprites["teclaRe2"].visible = false
  
  sprites["teclaRe2#"]=IconSprite.new(0,0,viewport)
  sprites["teclaRe2#"].setBitmap("Graphics/Pictures/Piano/teclaNeg")
  sprites["teclaRe2#"].x =444
  sprites["teclaRe2#"].y =170
  sprites["teclaRe2#"].visible = false
  
  sprites["teclaMi2"]=IconSprite.new(0,0,viewport)
  sprites["teclaMi2"].setBitmap("Graphics/Pictures/Piano/teclaDer")
  sprites["teclaMi2"].x =462
  sprites["teclaMi2"].y =170
  sprites["teclaMi2"].visible = false
  
  loop do
    Graphics.update
    Input.update
    
    #GRAFICOS
    if Input.press?(Input::SHIFT)
      #DoSos
      if Input.press?(Input::Q)
        sprites["teclaDo#"].visible = true
      else
        sprites["teclaDo#"].visible = false
      end  
      #ReSos
      if Input.press?(Input::W)
        sprites["teclaRe#"].visible = true
      else
        sprites["teclaRe#"].visible = false
      end  
      #FaSos
      if Input.press?(Input::E)
        sprites["teclaFa#"].visible = true
      else
        sprites["teclaFa#"].visible = false
      end  
      #SolSos
      if Input.press?(Input::ER)
        sprites["teclaSol#"].visible = true
      else
        sprites["teclaSol#"].visible = false
      end 
      #LaSos
      if Input.press?(Input::T)
        sprites["teclaLa#"].visible = true
      else
        sprites["teclaLa#"].visible = false
      end  
      #Do2Sos
      if Input.press?(Input::YI)
        sprites["teclaDo2#"].visible = true
      else
        sprites["teclaDo2#"].visible = false
      end  
      #Re2Sos
      if Input.press?(Input::U)
        sprites["teclaRe2#"].visible = true
      else
        sprites["teclaRe2#"].visible = false
      end  
    else  
      #Do
      if Input.press?(Input::Q)
        sprites["teclaDo"].visible = true
      else
        sprites["teclaDo"].visible = false
      end  
      #Re
      if Input.press?(Input::W)
        sprites["teclaRe"].visible = true
      else
        sprites["teclaRe"].visible = false
      end  
      #Mi
      if Input.press?(Input::E)
        sprites["teclaMi"].visible = true
      else
        sprites["teclaMi"].visible = false
      end 
      #Fa
      if Input.press?(Input::ER)
        sprites["teclaFa"].visible = true
      else
        sprites["teclaFa"].visible = false
      end 
      #Sol
      if Input.press?(Input::T)
        sprites["teclaSol"].visible = true
      else
        sprites["teclaSol"].visible = false
      end 
      #La
      if Input.press?(Input::YI)
        sprites["teclaLa"].visible = true
      else
        sprites["teclaLa"].visible = false
      end 
      #Si
      if Input.press?(Input::U)
        sprites["teclaSi"].visible = true
      else
        sprites["teclaSi"].visible = false
      end 
      #Do2
      if Input.press?(Input::I)
        sprites["teclaDo2"].visible = true
      else
        sprites["teclaDo2"].visible = false
      end 
      #Re2
      if Input.press?(Input::O)
        sprites["teclaRe2"].visible = true
      else
        sprites["teclaRe2"].visible = false
      end 
      #Mi2
      if Input.press?(Input::P)
        sprites["teclaMi2"].visible = true
      else
        sprites["teclaMi2"].visible = false
      end       
    end  #end if
    
    #SONIDOS
      if Input.press?(Input::SHIFT)
      #DoSos
      if Input.trigger?(Input::Q)
        pbSEPlay("Notas/DoSos")
      end  
      #ReSos
      if Input.trigger?(Input::W)
        pbSEPlay("Notas/ReSos")
      end  
      #FaSos
      if Input.trigger?(Input::E)
        pbSEPlay("Notas/FaSos")
        
      end  
      #SolSos
      if Input.trigger?(Input::ER)
        pbSEPlay("Notas/SolSos")
        
      end 
      #LaSos
      if Input.trigger?(Input::T)
        pbSEPlay("Notas/LaSos")
       
      end  
      #Do2Sos
      if Input.trigger?(Input::YI)
        pbSEPlay("Notas/Do2Sos")
        
      end  
      #Re2Sos
      if Input.trigger?(Input::U)
        pbSEPlay("Notas/Re2Sos")
        
      end  
    else  
      #Do
      if Input.trigger?(Input::Q)
        pbSEPlay("Notas/Do")

      end  
      #Re
      if Input.trigger?(Input::W)
        pbSEPlay("Notas/Re")
  
      end  
      #Mi
      if Input.trigger?(Input::E)
        pbSEPlay("Notas/Mi")
    
      end 
      #Fa
      if Input.trigger?(Input::ER)
        pbSEPlay("Notas/Fa")
        
      end 
      #Sol
      if Input.trigger?(Input::T)
        pbSEPlay("Notas/Sol")
       
      end 
      #La
      if Input.trigger?(Input::YI)
        pbSEPlay("Notas/La")
       
      end 
      #Si
      if Input.trigger?(Input::U)
        pbSEPlay("Notas/Si")
       
      end 
      #Do2
      if Input.trigger?(Input::I)
        pbSEPlay("Notas/Do2")
       
      end 
      #Re2
      if Input.trigger?(Input::O)
        pbSEPlay("Notas/Re2")
        
      end 
      #Mi2
      if Input.trigger?(Input::P)
        pbSEPlay("Notas/Mi2")
       
      end       
    end  #end if
    
    if Input.trigger?(Input::B)
      pbSEPlay("select")
      pbFadeOutAndHide(sprites){pbUpdateSpriteHash(sprites)}
      pbDisposeSpriteHash(sprites)
      viewport.dispose if viewport
      $game_system.bgm_restore
      break
    end
    
    #
  end #end loop  
end  